package cm.com.carlamanda.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cm.com.carlamanda.dao.InputParamDAO;
import cm.com.carlamanda.domain.InputParam;
import cm.com.carlamanda.domain.Page;
import cm.com.carlamanda.service.InputParamService;
import cm.com.carlamanda.util.StringUtil;

@Service
public class InputParamServiceImpl implements InputParamService {
    @Autowired
    private InputParamDAO inputParamDao;
    
    @Override
    public List<InputParam> getParamListByInterfaceId(String interfaceId) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("interfaceId", interfaceId);
        return inputParamDao.search(map);
    }

    @Override
    public void add(InputParam inputParam) {
        if(StringUtil.isEmpty(inputParam.getId())){
            inputParam.setId(UUID.randomUUID().toString());
        }
        inputParamDao.insert(inputParam);
    }

    @Override
    public void del(InputParam inputParam) {
        inputParamDao.del(inputParam);
    }

    @Override
    public void update(InputParam inputParam) {
        inputParamDao.update(inputParam);
    }

    @Override
    public List<InputParam> search(InputParam inputParam, Page page) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("interfaceId", inputParam.getInterfaceId());
        map.put("name", inputParam.getName());
        map.put("description", inputParam.getDescription());
        map.put("startPos", page.getStartPos());
        map.put("endPos", page.getEndPos());
        map.put("sortColumn", page.getSortColumn());
        map.put("sortAsc", page.getSortAsc());
        int count =inputParamDao.searchInputParamCount(map);
        page.setTotalCount(count);
        page.setTotalPage(count);
        return inputParamDao.search(map);
    }

    @Override
    public InputParam get(String id) {
        return inputParamDao.get(id);
    }

    @Override
    public void batchAddParams(List<InputParam> params) {
        inputParamDao.batchInsertInputParam(params);        
    }

}
